﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>公告管理</title>
    <link href="~/Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "News", "KeyName": "News" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限
                            $("#ui_News_dg").datagrid({       //初始化datagrid
                                url: "/News/GetAllNewsInfo",
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true, multiSort: false,
                                idField: 'id',
                                sortName: 'UpdateTime',
                                sortOrder: 'desc',
                                pageList: [20, 40, 60, 80, 100],
                                frozenColumns: [[
                                                { field: 'ck', checkbox: true },
                                                //{ field: 'id', title: '公告ID', width: 60 },
                                                { field: 'ftypename', title: '所属分类', width: 100 },
                                                { field: 'ftitle', title: '标题', width: 250 }]],
                                columns: [[
                                           {
                                               field: 'fcontent', title: '内容', width: 800
                                           }
                                           //,{ field: 'UpdateBy', title: '最后更新人', width: 80 },
                                           //{ field: 'UpdateTime', title: '最后更新时间', width: 130 }
                                ]],
                                toolbar: toolbar.length == 0 ? null : toolbar
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
            //回车搜索
            $("#ui_News_search").find('input').on('keyup', function (event) {
                if (event.keyCode == '13') {
                    searchdata();
                }
            })
        });

        function CloseAddNewsDialog() {
            $('#AddNews').dialog('destroy');
            $("#ui_News_dg").datagrid("reload");
        }

        //新增
        function AddNews() {
            var content = '<iframe src="/News/NewsAdd" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>';
            $("<div/>").dialog({
                id: "AddNews",
                content: content,
                title: "添加公告",
                height: window.screen.availHeight - 230,
                width: 800,
                modal: true,
                onClose: function () {
                    $("#ui_News_dg").datagrid("reload");
                }
            });
        }

        //关闭弹出层
        function CloseEditNewsDialog() {
            $('#EditNews').dialog('destroy');
            $("#ui_News_dg").datagrid("reload");
        }

        //修改
        function EditNews() {
            var row = $("#ui_News_dg").datagrid("getChecked");
            if (row.length < 1) {
                $.show_alert("提示", "请先选择要修改的公告");
                return;
            }
            var content = '<iframe src="/News/NewsEdit?id=' + row[0].id + '" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>';
            $("<div/>").dialog({
                id: "EditNews",
                content: content,
                title: "修改公告",
                height: window.screen.availHeight - 230,
                width: 800,
                modal: true,
                onClose: function () {
                    $("#ui_News_dg").datagrid("reload");
                }
            });
        }

        //删除
        function DelNews() {
            var rows = $("#ui_News_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要删除的公告");
                return;
            }

            $.messager.confirm('提示', '确定删除选中行吗？', function (r) {
                if (r) {
                    var NewsIDs = "";
                    $.each(rows, function (i, row) {
                        NewsIDs += row.id + ",";
                    });
                    NewsIDs = NewsIDs.substring(0, NewsIDs.length - 1);
                    $.ajax({
                        url: "/News/DelNewsByIDs",
                        data: {
                            IDs: NewsIDs
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_News_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }

        //搜索
        function searchdata() {
            var typeid = $("#selcomboxtype").combobox('getValues').toString();
            $("#ui_News_dg").datagrid('load', {
                frequstid: typeid,
                ftitle: $("#txtSearchFTitle").val()
            });
            $("#ui_News_dg").datagrid('clearSelections').datagrid('clearChecked');
        }

    </script>
</head>
<body>
    <div id="ui_News_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'north',split:true,border:true,collapsed:true" title="条件搜索" style="height:72px;">
            <div id="ui_News_search">
                <table class="tableForm" style="height:28px;background:#f5f5f5;">
                    <tr>

                        <th height="20px">
                            公告标题：
                        </th>
                        <td>
                            <input name="txtSearchFTitle" id="txtSearchFTitle" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>
                        <th height="20px">
                            公告：
                        </th>
                        <td style="padding-right:50px;">
                            <input class="easyui-combobox" id="selcomboxtype" name="selcomboxtype" style="width:150px;height:22px;"
                                   data-options="
                            url:'/NewsType/GetAllNewsTypeDrop',
                            editable:false,
                            valueField:'id',
                            textField:'ftypename',
                            multiple:false" />
                            <img style="cursor: pointer; vertical-align: middle;" onclick="$('#comboxtype').combobox('clear');"
                                 alt="清空" title="清空" src="../Content/themes/icon/edit-clear.png" />
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                               onclick="searchdata();">搜索</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div data-options="region:'center',border:false">
            <table id="ui_News_dg" data-options="fit:true,border:false"></table>
        </div>
    </div>
</body>
</html>

